﻿using System;
using System.ComponentModel;
using System.Security;
using System.Xml.Serialization;
using LisenceUtils.Enums;

namespace LisenceUtils
{
    public delegate string GetUidEventHandle();

    public abstract class LicenseEntity
    {
        [Browsable(false)]
        [XmlIgnore]
        [ShowInLicenseInfo(false)]
        public string AppName { get; protected set; }

        [Browsable(false)]
        [XmlElement("Uid")]
        [ShowInLicenseInfo(false)]
        public string Uid { get; set; }

        [Browsable(false)]
        [XmlElement("Type")]
        [ShowInLicenseInfo(true, "Type", ShowInLicenseInfoAttribute.FormatType.EnumDescription)]
        public LicenseTypes Type { get; set; }

        [Browsable(false)]
        [XmlElement("CreateDateTime")]
        [ShowInLicenseInfo(true, "Creation Time", ShowInLicenseInfoAttribute.FormatType.DateTime)]
        public DateTime CreateDateTime { get; set; }

        public LicenseStatus LicenseStatus { get; set; }
        public string ValidationMsg { get; set; }
        public event GetUidEventHandle GetUidEvent;

        public string OnGetUid()
        {
            return GetUidEvent?.Invoke();
        }

        public abstract string GenerateLicenseBase64String(byte[] certPrivateKeyData,
            SecureString certFilePwd);

        public abstract LicenseEntity ParseLicenseFromBase64String(string licenseString,
            byte[] certPubKeyData);
    }
}